﻿#include "MenuBarPropertyEditEntry.h"

#include <QMenuBar>
#include "ObjectPropertyEditEntryFactory.h"
REGISTER_PROPERTY_EDIT_ENTRY(MenuBar)

#include "BooleanEditEntry.h"

struct MenuBarPropertyEditEntry::MenuBarPropertyEditEntryPrivate {
    QPointer<QMenuBar> object;
    QPointer<BooleanEditEntry> entryDefaultUp;
    QPointer<BooleanEditEntry> entryNativeMenuBar;
};

MenuBarPropertyEditEntry::~MenuBarPropertyEditEntry() { }

MenuBarPropertyEditEntry::MenuBarPropertyEditEntry(QWidget *parent) : PropertyEditEntry {parent} {
    p.reset(new MenuBarPropertyEditEntryPrivate);
    initUi();
    retranslateUi();
}

void MenuBarPropertyEditEntry::setObject(void *object) {
    p->object = static_cast<QMenuBar*>(object);
}

void MenuBarPropertyEditEntry::onTick() {
    if(!p->object || !isVisible()) {
        return ;
    }

    p->entryDefaultUp->setValue(p->object->isDefaultUp());
    p->entryNativeMenuBar->setValue(p->object->isNativeMenuBar());
}

void MenuBarPropertyEditEntry::initUi() {
    p->entryDefaultUp = new BooleanEditEntry;
    appendChildEntry(p->entryDefaultUp);
    connect(p->entryDefaultUp, &BooleanEditEntry::valueChanged, [=](bool value) {
        p->object->setDefaultUp(value);
    });

    p->entryNativeMenuBar = new BooleanEditEntry;
    appendChildEntry(p->entryNativeMenuBar);
    connect(p->entryNativeMenuBar, &BooleanEditEntry::valueChanged, [=](bool value) {
        p->object->setNativeMenuBar(value);
    });
}

void MenuBarPropertyEditEntry::retranslateUi() {
    setTitle(tr("QMenuBar"));
    p->entryDefaultUp->setTitle(tr("defaultUp"));
    p->entryNativeMenuBar->setTitle(tr("nativeMenuBar"));
}
